package com.tx.review.thread_.state;

import java.util.concurrent.TimeUnit;

/**
 * join测试
 *      插队
 * @author ：tx
 * @version:
 */
public class JoinDemo {
    public static void main(String[] args) {
        Study study = new Study();
        study.start();
    }

    static class Study extends Thread{
        @Override
        public void run() {
            System.out.println("我准备学习了");
            Play play = new Play();
            play.start();
            //不加join，就相当于有Study和Play两个线程，互不影响
            //加了join：表示我要先处理play线程
            try {
                play.join();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

            System.out.println("我学完了");
        }
    }


    static class Play extends Thread{
        @Override
        public void run() {
            System.out.println("还是玩会游戏,我亚索贼6");
            try { TimeUnit.SECONDS.sleep(3); } catch (InterruptedException e) { e.printStackTrace(); }
            System.out.println("一看战绩0-5 -> game over");
        }
    }
}
